\# .TH gsocket 1 "08 October 2020" "1.0" "gssocket man page"
.Dd March 02, 2021
.Dt gsocket 1
.Os
.Sh NAME
.Nm gsocket
.Nd connect like there is no firewall. Securely.
.Sh SYNOPSIS
.Nm gsocket
.Op Fl qT
.Op Fl s Ar secret
.Op Fl k Ar keyfile
.Op Fl p Ar port
.Op Ar program
.Op Ar args ...
.Sh DESCRIPTION
The
.Nm
tool can be used to enable a program to communicate through a firewall in situations where it would not be possible to establish a direct connection to another host/workstation (NATed/firewalled). The typical scenario is two workstations that are on separate private networks and behind separate firewalls. The
.Nm
tool hijacks the network library functions (such as connect() and accept()) of the program and encrypts and redirects the traffic through the Global Socket Relay Network (GSRN). 
.Pp
Neither workstation needs to open a port in their firewall nor accept incoming TCP connections.
.Pp
The connection is end-2-end encrypted using SRP (RFC 5054) with AES-256 and a 4096 Prime. The GSRN sees only the encrypted traffic. 
.Pp
Common uses include:
.Pp
.Bl -bullet -offset indent -compact
.It
ssh from one workstation to another
.It
OpenVPN between two workstations
.It
netcat between two workstations
.It
and much, much more.
.El
.Pp
 ...while both workstations are behind NAT and firewalled.
.Pp
Abandon the thought of IP addresses and port numbers: Two programs should be able to communicate with each other as long as they know the same secret (rather than each other's IP address and port number). The
.Nm
tools establishes such a connection regardless and independent of the local IP address or geographical location. It does so by analyzing the program and replacing the IP Layer with its own transport through GSRN. The connection is end-2-end encrypted. The GSRN sees only the encrypted traffic.
.Pp
The typical scenario is a client/server arrangement such as ssh and sshd: Connections by ssh to any hostname ending in '.gsocket' are redirected (through the GSRN) to the (firewalled) sshd server.
.Pp
The redirection is done per program (and limited to that program only). The
.Nm
tool does not change the routing table and does not change the NAT nor the firewall settings. It does not require superuser privileges either.
.Pp
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl s Ar secret
A secret chosen by the user. Both ends need to use the same secret to connect.
.It Fl k Ar file
A file containing the secret.
.It Fl g
Generate a secure random secret and output it to standard output.
.It Fl q
Quiet mode. Do not output any warnings or errors.
.It Fl T
Use TOR. The
.Nm
tool will connect through TOR to the GSRN. This requires TOR to be installed and running.
.It Fl p Ar port
TCP port range of listening ports to redirect [default=all].
.El
.Pp
Connections to any hostname ending in '*.gsocket' or to the IP Address '127.31.33.7' are redirected through the GSRN.
.Pp
Connections to any hostname ending in '*.thc' or to the IP Address '127.31.33.8' are first redirected through TOR and then through the GSRN.
.Sh EXAMPLES
.Nm Example 1
- OpenSSH between two firewalled workstations:
.Pp
Server:
.Dl $ gsocket -s MySecret /usr/sbin/sshd
Client:
.Dl $ gsocket -s MySecret ssh xaitax@gsocket
.Pp
.Nm Example 2
- netcat between two firewalled workstations:
.Pp
Server:
.Dl $ gsocket -s MySecret nc -lp 31337
Client:
.Dl $ gsocket -s MySecret nc gsocket 31337
.Pp
.Nm Example 3
- OpenVPN between two firewalled workstations:
.Pp
Server:
.Dl $ gsocket -s MySecret openvpn --dev tun1 --proto tcp-server --ifconfig 10.9.8.1 10.9.8.2
Client:
.Dl $ gsocket -s MySecret openvpn --dev tun1 --proto tcp-client --ifconfig 10.9.8.2 10.9.8.1 --remote gsocket
.Pp
.Nm Example 4
- IRCD between two firewalled workstations:
.Pp
Server:
.Dl $ gsocket -s MySecret inspircd --nolog --nofork
Client:
.Dl $ gsocket -s MySecret irssi -c gsocket
.Pp
.Nm Example 5
- Socat between two firewalled workstations:
.Pp
Server:
.Dl $ gsocket -s MySecret socat - TCP_LISTEN:31337
Client:
.Dl $ gsocket -s MySecret socat - TCP:gsocket:31337
.Pp
.Sh SYSTEMCTL INSTALLATION
It is possible to make any service/daemon accessible through any firewall. The service is then only acessible through the GSRN and only if the client knows the secret. No port or service is exposed to the public Internet and the existence of the service remains hidden. This example makes openssh-server (sshd) accessible through the GSRN. Nobody, not even the GSRN operators, have access to the port, daemon or service (they do not know the secret). The new service coexists with the existing openssh-server and does not interfere with the existing openssh-server.
.Pp
1. Copy /etc/systemd/system/sshd to /etc/systemd/system/gs-sshd
.Pp
2. Edit /etc/systemd/system/gs-sshd and change this line:
.Dl ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
to
.Dl ExecStart=gsocket -s MySecret /usr/sbin/sshd -D $SSHD_OPTS
.Pp
3. Start the newly created service
.Dl # systemctl start gs-sshd
.Pp
4. Check the status
.Dl # systemctl status gs-sshd
.Pp
5. Connect from any other host to the newly created (hidden) openssh-server:
.Dl $ gsocket -s MySecret ssh user@gsocket
.Pp
.Sh TESTING
The
.Nm
tool uses the LD_PRELOAD method to hijack network calls from the calling process. It then concatenates the port number to the secret and spwans a gs-netcat process to forward the TCP connection. The setup can be tested with gs-netcat.
.Pp
.Nm Test 1
- gsocket server and gs-netcat client:
.Pp
Server:
.Dl $ gsocket -s MySecret nc -lp 1234 # TCP port is 1234
Client:
.Dl $ gs-netcat -s 1234-MySecret      # Notice `<port>-<SECRET>`
.Pp
.Nm Test 2
- gsocket client and gs-netcat server:
.Pp
Server:
.Dl $ gs-netcat -s 1234-MySecret -l
Client:
.Dl $ gsocket -s MySecret nc blah.gsocket 1234
.Pp
Internally the
.Nm
tool (on the client side) forks a background gs-netcat process listening on 127.31.33.7 on a random TCP port. The
.Nm
tool then detects `nc` trying to resolve `blah.gsocket` and returns 127.31.33.7 to `nc`. The `nc` process then connects to 127.31.33.7 instead and the gs-netcat process (that got started automatically) takes the connection and forwards the traffic via the GSRN. The `nc` tool can also directly connect to 127.31.33.7 instead of blah.gsocket (for testing):
.Pp
Client:
.Dl $ gsocket -s MySecret nc -n 127.31.33.7 1234
.Pp
.Nm Test 3
- SSHD via gsocket:
.Pp
Server:
.Dl $ gsocket -s MySecret /usr/sbin/sshd -D -p 1234
Client:
.Dl $ gs-netcat -s 1234-MySecret
.Dl SSH-2.0-OpenSSH_8.4p1 Debian-2
.Pp
Use gs-netcat as a port-forwarder and ssh to connect:
.Pp
Client:
.Dl $ gs-netcat -s 1234-MySecret -p 44222
.Dl $ ssh -p 44222 user@127.1
.Pp
.Nm Test 4
- SSH via gsocket:
.Pp
On the server start a gs-netcat port forward to forward incoming GSRN connections to the SSHD on localhost:
.Pp
Server:
.Dl $ gs-netcat -s 22-MySecret -l -d 127.0.0.1 -p 22
Client:
.Dl $ gsocket -s MySecret ssh user@gsocket
.Pp
.Sh ENVIRONMENT
The following environment variables can be set to control the behavior of
.Nm
.Pp
.Nm GSOCKET_SOCKS_IP
.Dl Specify the IP address of the TOR server (or any other SOCKS server). Use together with -T. Default is 127.0.0.1.
.Pp
.Nm GSOCKET_SOCKS_PORT
.Dl The port number of the TOR server (or any other SOCKS server). Use together with -T. Default is 9050.
.Pp
.Nm GSOCKET_ARGS
.Dl A string containing additional command line parameters. First the normal command line parameters are processed and then the command line parameters from GSOCKET_ARGS.
.Sh SECURITY
Passing the password as command line parameter is not secure. Consider using the -k option or GSOCKET_ARGS or enter the password when prompted:
.Pp
.Dl $ gsocket -k <file>
.Pp
.Dl $ export GSOCKET_ARGS="-s MySecret"
.Dl $ gsocket
.Pp
.Nm 1.
The security is end-2-end. This means from user-2-user (and not just to the GSRN). The GSRN relays only (encrypted) data to and from the users.
.Pp
.Nm 2.
The session is 256 bit and ephemeral. It is freshly generated for every session and generated randomly (and is not based on the password). It uses OpenSSL's SRP with AES-256 and a 4096 Prime.
.Pp
.Nm 3.
The password can be 'weak' without weakening the security of the session. A brute force attack against a weak password requires a new TCP connection for every guess.
.Pp
.Nm 4.
Do not use stupid passwords like 'password123'. Malice might pick the same (stupid) password by chance and connect. If in doubt use gs-netcat -g to generate a strong one. Alice's and Bob's password should at least be strong enough so that Malice can not guess it by chance while Alice is waiting for Bob to connect.
.Pp
.Nm 5.
If Alice shares the same password with Bob and Charlie and either one of them connects then Alice can not tell if it is Bob or Charlie who connected.
.Pp
.Nm 6.
Assume Alice shares the same password with Bob and Malice. When Alice stops listening for a connection then Malice could start to listen for the connection instead. Bob (when opening a new connection) can not tell if he is connecting to Alice or to Malice. Use -a <token> if you worry about this. TL;DR: When sharing the same password with a group larger than 2 then it is assumed that everyone in that group plays nicely. Otherwise use SSH over the GS/TLS connection.
.Pp
.Nm 7.
SRP has Perfect Forward Secrecy. This means that past sessions can not be decrypted even if the password becomes known.
.Sh NOTES
The latest version is available from https://github.com/hackerschoice/gsocket/.
.Sh SEE ALSO
.Xr gs-netcat(1) ,
.Xr gs-sftp(1) ,
.Xr gs-mount(1) ,
.Xr blitz(1) ,
.Xr nc(1) ,
.Xr socat(1)
.Sh BUGS
Efforts have been made to have
.Nm
"do the right thing" in all its various modes. If you believe that it is doing the wrong thing under whatever circumstances, please notify me (skyper@thc.org) and tell me how you think it should behave.
